﻿namespace Devil.Persistent
{
    public partial class PersistentSystem
    {

        System.Action<IPersistentMeta> mOnSaveBegin;
        System.Action<IPersistentMeta> mOnLoadBegin;
        PersistentDataAction mOnLoaded;
        PersistentDataAction mOnSaved;

        public event System.Action<IPersistentMeta> OnSaveDataBegin
        {
            add
            {
                lock (_singletonLock)
                {
                    if (mReleased)
                        throw new System.InvalidOperationException("The persistent system was destroied.");
                    mOnSaveBegin += value;
                }
            }
            remove
            {
                lock (_singletonLock)
                {
                    mOnSaveBegin -= value;
                }
            }
        }
        public event System.Action<IPersistentMeta> OnLoadDataBegin
        {
            add
            {
                lock (_singletonLock)
                {
                    if (mReleased)
                        throw new System.InvalidOperationException("The persistent system was destroied.");
                    mOnLoadBegin += value;
                }
            }
            remove
            {
                lock (_singletonLock)
                {
                    mOnLoadBegin -= value;
                }
            }
        }

        public event PersistentDataAction OnPersistentDataLoaded
        {
            add
            {
                lock (_singletonLock)
                {
                    if (mReleased)
                        throw new System.InvalidOperationException("The persistent system was destroied.");
                    mOnLoaded += value;
                }
            }
            remove
            {
                lock (_singletonLock)
                {
                    mOnLoaded -= value;
                }
            }
        }

        public event PersistentDataAction OnPersistentDataSaved
        {
            add
            {
                lock (_singletonLock)
                {
                    if (mReleased)
                        throw new System.InvalidOperationException("The persistent system was destroied.");
                    mOnSaved += value;
                }
            }
            remove
            {
                lock (_singletonLock)
                {
                    mOnSaved -= value;
                }
            }
        }

    }
}
